<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.1.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css" integrity="sha256-DfWjNxDkM94fVBWx1H5BMMp0Zq7luBlV8QRcSES7s+0=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"example.com","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.11.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="Windows OS Handle获取进程句柄（HANDLE）和窗口句柄（HWND）当在一台主机中时，可以根据进程的ID获取进程句柄也可以根据进程名称来获取进程句柄， 获取窗口句柄：当想获取窗口句柄时，可以使用窗口的类名或窗口的标题来获取窗口句柄">
<meta property="og:type" content="article">
<meta property="og:title" content="Windows OS Handle">
<meta property="og:url" content="http://example.com/2021/11/24/Windows-OS-Handle/index.html">
<meta property="og:site_name" content="Youan">
<meta property="og:description" content="Windows OS Handle获取进程句柄（HANDLE）和窗口句柄（HWND）当在一台主机中时，可以根据进程的ID获取进程句柄也可以根据进程名称来获取进程句柄， 获取窗口句柄：当想获取窗口句柄时，可以使用窗口的类名或窗口的标题来获取窗口句柄">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-11-23T16:00:00.000Z">
<meta property="article:modified_time" content="2022-12-06T08:49:04.356Z">
<meta property="article:author" content="lee">
<meta property="article:tag" content="windows">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://example.com/2021/11/24/Windows-OS-Handle/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://example.com/2021/11/24/Windows-OS-Handle/","path":"2021/11/24/Windows-OS-Handle/","title":"Windows OS Handle"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Windows OS Handle | Youan</title>
  





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Youan</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">好记性不如烂笔头</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Windows-OS-Handle"><span class="nav-number">1.</span> <span class="nav-text">Windows OS Handle</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E8%BF%9B%E7%A8%8B%E5%8F%A5%E6%9F%84%EF%BC%88HANDLE%EF%BC%89%E5%92%8C%E7%AA%97%E5%8F%A3%E5%8F%A5%E6%9F%84%EF%BC%88HWND%EF%BC%89"><span class="nav-number">1.1.</span> <span class="nav-text">获取进程句柄（HANDLE）和窗口句柄（HWND）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E7%AA%97%E5%8F%A3%E5%8F%A5%E6%9F%84%EF%BC%9A"><span class="nav-number">1.2.</span> <span class="nav-text">获取窗口句柄：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%BF%9B%E7%A8%8B%E5%8F%A5%E6%9F%84%E5%92%8C%E7%AA%97%E5%8F%A3%E5%8F%A5%E6%9F%84%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9A"><span class="nav-number">1.3.</span> <span class="nav-text">进程句柄和窗口句柄的区别：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8D%AE%E7%AA%97%E5%8F%A3%E5%8F%A5%E6%9F%84%E5%BE%97%E5%88%B0%E8%BF%9B%E7%A8%8B%E5%8F%A5%E6%9F%84%EF%BC%9A"><span class="nav-number">1.4.</span> <span class="nav-text">据窗口句柄得到进程句柄：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HANDLE-%E5%92%8C-HWND-%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="nav-number">1.5.</span> <span class="nav-text">HANDLE 和 HWND 的区别:</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lee</p>
  <div class="site-description" itemprop="description">记录备份</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">10</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wslmh" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wslmh" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:wslmh@outlook.com" title="E-Mail → mailto:wslmh@outlook.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/11/24/Windows-OS-Handle/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lee">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Youan">
      <meta itemprop="description" content="记录备份">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Windows OS Handle | Youan">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Windows OS Handle
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-11-24 00:00:00" itemprop="dateCreated datePublished" datetime="2021-11-24T00:00:00+08:00">2021-11-24</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2022-12-06 16:49:04" itemprop="dateModified" datetime="2022-12-06T16:49:04+08:00">2022-12-06</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/windows/" itemprop="url" rel="index"><span itemprop="name">windows</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="Windows-OS-Handle"><a href="#Windows-OS-Handle" class="headerlink" title="Windows OS Handle"></a>Windows OS Handle</h1><h2 id="获取进程句柄（HANDLE）和窗口句柄（HWND）"><a href="#获取进程句柄（HANDLE）和窗口句柄（HWND）" class="headerlink" title="获取进程句柄（HANDLE）和窗口句柄（HWND）"></a>获取进程句柄（HANDLE）和窗口句柄（HWND）</h2><p>当在一台主机中时，可以根据进程的ID获取进程句柄<br>也可以根据进程名称来获取进程句柄，</p>
<h2 id="获取窗口句柄："><a href="#获取窗口句柄：" class="headerlink" title="获取窗口句柄："></a>获取窗口句柄：</h2><p>当想获取窗口句柄时，可以使用窗口的类名或窗口的标题来获取窗口句柄</p>
<span id="more"></span>


<h2 id="进程句柄和窗口句柄的区别："><a href="#进程句柄和窗口句柄的区别：" class="headerlink" title="进程句柄和窗口句柄的区别："></a>进程句柄和窗口句柄的区别：</h2><p>窗口句柄和进程句柄是不一样的，一个进程是可以有多个窗口句柄的，通过窗口句柄可以得到进程句柄，返过来就比较麻烦了，因为一个进程可以有多个窗口，但是得到父窗口还是比较容易的。</p>
<h2 id="据窗口句柄得到进程句柄："><a href="#据窗口句柄得到进程句柄：" class="headerlink" title="据窗口句柄得到进程句柄："></a>据窗口句柄得到进程句柄：</h2><p>如何查找到当前窗口所在进程的相关数据，如进程句柄、进程：<br>1、首先通过类名 或 窗体的名字 得到映射窗口的窗口句柄  windows提供的API函数 FindWindow（）函数就能得到这个句柄HWND FindWondow（lpclassname,lpwindowsname）<br>2、然后通过得到的窗口句柄得到窗口所在进程的ID，GetWindowThreadProcessId（窗口句柄，所在进程的ID）；<br>3、再通过进程的ID得到进程的进程句柄；<br>句柄&#x3D;openProcess（，，句柄）；</p>
<h2 id="HANDLE-和-HWND-的区别"><a href="#HANDLE-和-HWND-的区别" class="headerlink" title="HANDLE 和 HWND 的区别:"></a>HANDLE 和 HWND 的区别:</h2><p>HWND是HANDLE的一种，但是HANDLE并不是HWND。<br>HANDLE是操作系统一系列内核对象的句柄。<br>HWND仅是窗口对象的句柄。</p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/windows/" rel="tag"># windows</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/07/06/Windows-DirectUI/" rel="prev" title="DirectUI介绍">
                  <i class="fa fa-chevron-left"></i> DirectUI介绍
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2022/05/08/Hexo-Github%20Pages/" rel="next" title="Hexo + Github Page 建立个人博客">
                  Hexo + Github Page 建立个人博客 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lee</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
